import {SONG_LIST} from '../api'
export default (state,action)=>{
  state = state || {songList:[],topInfo:{},totalSongNum:0,updateTime:'',currentSong:{}};
  switch(action.type){
    case 'LIST_INIT':
      return {songList:action.songList,topInfo:action.topInfo,totalSongNum:action.totalSongNum,updateTime:action.updateTime}
    // case 'CURRENT_SONG':
    //   const currentSong=state.songList.find(value=>(value.songMid === action.mid))
    //   return {...state,currentSong}
    default:
      return state;
  }
}

export const getSongList = (id) => (dispatch) => {
  fetch(SONG_LIST + id).then(response=>response.json()).then(result=>{
    dispatch({type:'LIST_INIT',songList:result.data.songList,topInfo:result.data.topInfo,totalSongNum:result.data.totalSongNum,updateTime:result.data.updateTime})
  })
}

// export const setCurrentSong = (mid) =>(dispatch)=>{
//   dispatch({type:'CURRENT_SONG',mid})
// }